home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / forth / amiga / amigaker.arc / 07.dos < prev    next >
Text File  |  1988-01-09  |  6KB  |  163 lines

  1. ;
  2. ;  07.dos
  3. ;  Support routines for dos, not the regular forth block stuff.
  4. ;  The dos routines allow two levels of interface, raw and buffered.
  5. ;  The raw routines are accessable through the low level calls, provided
  6. ;  by dos. Calls are e.g. Read, Write, Seek. Buffers are assigned by the
  7. ;  user.
  8. ;  Buffered file useage is through specific calls to routines:
  9. ;    getc, putc, gets, puts and ungetc. ( if implemented )
  10. ;  The buffers are 512 bytes long and are invisible. All operations on
  11. ;  the files take in-file and file as pointers to file info buffers fib's.
  12. ;  A fib is:
  13. ;   0   long     file-handle
  14. ;   4   long     'buffer
  15. ;   8   word     buffersize  (default 512, max 32k )
  16. ;   10  word     flags
  17. ;   12  long     'nextchar
  18. ;   16  word     # char remaining (writing) or # char in the buffer (read)
  19. ;   18  long     link              ( to close files on exit )
  20. ;   22  ....     name  null terminated with preceding size byte, actually not
  21. ;              part of the fib, but in files declared by file:, the name
  22. ;              will follow the fib.
  23. ;
  24. ;     flags:   bit 0    1=eof
  25. ;              bit 15   1=dirty  0=clear
  26. ;
  27.  
  28. ; All files, whether raw or buffered, have an fib. The raw files do not
  29. ; use the information from flags on. The file will be closed if forth is
  30. ; exitted. The buffer allocated with Allocmem will be freed up.
  31.  
  32. ; NOTE DO NOT USE BUFFERS LARGER THEN 32K.
  33.  
  34. ; Make four links for dos vocabulary
  35.  
  36. doslink0          set      0
  37. doslink1          set      0
  38. doslink2          set      0
  39. doslink3          set      0
  40.  
  41. * dos             Vocabulary, coincides with a Library
  42.                   dc.w     -1
  43.                   dc.l     link0
  44. link0             set      *-4
  45.                   dc.b     $83,'do',$80!'s'
  46.                   cnop     0,2
  47. _dos              dc.l     vocabulary_does
  48.                   dc.l     dosLink0,dosLink1,dosLink2,dosLink3,voc_link
  49. voc_link          set      *-4
  50.  
  51. * DosBase         (s -- addr )  Holds the DosBase, the Library vector.
  52.                   dc.w     -1
  53.                   dc.l     doslink0
  54. doslink0          set      *-4
  55.                   dc.b     $87,'DosBas',$80!'e'
  56.                   cnop     0,2
  57. _DosBase          dc.l     docreate
  58. dosbase           dc.l     0
  59.                   dc.l     lib_link       ;linked list for libraries.
  60. lib_link          set      *-4
  61.  
  62. * doscall         (s flag offset mask -- ) Creates an entry in the
  63. ; dictionary, which calls the Dos library
  64.                   dc.w     -1
  65.                   dc.l     doslink0
  66. doslink0          set      *-4
  67.                   dc.b     $87,'doscal',$80!'l'
  68.                   cnop     0,2
  69. _doscall          dc.l     nest
  70.                   dc.l     _create,_w_comma,_w_comma,_w_comma
  71.                   dc.l     _nest_semi_colon_code
  72. dosbased          move.l   dosbase,a0
  73.                   jmp      callrom
  74.  
  75. * Open-Dos        (s -- )  Opens the library, aborts if unable to open.
  76.                   dc.w     -1
  77.                   dc.l     doslink3
  78. doslink3          set      *-4
  79.                   dc.b     $88,'Open-Do',$80!'s'
  80.                   cnop     0,2
  81. _Open_Dos         dc.l     nest
  82.                   dc.l     _nest_quote
  83.                   dc.b     12,'dos.library',0
  84.                   cnop     0,2
  85.                   dc.l     _drop,_0,_OpenLibrary,_dup,_0_equal
  86.                   dc.l     _nest_abort_quote
  87.                   dc.b     19,'Unable to open Dos',0
  88.                   cnop     0,2
  89.                   dc.l     _DosBase,_store,_exit
  90.  
  91. * Close-Dos       (s -- )   Close Dos library
  92.                   dc.w     -1
  93.                   dc.l     doslink3
  94. doslink3          set      *-4
  95.                   dc.b     $89,'Close-Do',$80!'s'
  96.                   cnop     0,2
  97. _Close_Dos        dc.l     nest
  98.                   dc.l     _DosBase,_fetch,_DosBase,_off
  99.                   dc.l     _CloseLibrary
  100.                   dc.l     _exit
  101.  
  102. * Open            (s accessMode 'name -- file-handle )
  103. ; Calls Dos Lib function Open. Note the order of parameters.
  104.                   dc.w     -1
  105.                   dc.l     doslink3
  106. doslink3          set      *-4
  107.                   dc.b     $84,'Ope',$80!'n'
  108.                   cnop     0,2
  109. _Open             dc.l     dosbased
  110.                   dc.w     %110,$ffe2,-1
  111.  
  112. * Close           (s file-handle -- )
  113. ; Calls Dos Lib function Close
  114.                   dc.w     -1
  115.                   dc.l     doslink3
  116. doslink3          set      *-4
  117.                   dc.b     $85,'Clos',$80!'e'
  118.                   cnop     0,2
  119. _Close            dc.l     dosbased
  120.                   dc.w     %10,$ffdc,0
  121.  
  122. * Read            (s length buffer file -- length )
  123. ; Calls Dos Read function. Returns actual bytes read.
  124.                   dc.w     -1
  125.                   dc.l     doslink2
  126. doslink2          set      *-4
  127.                   dc.b     $84,'Rea',$80!'d'
  128.                   cnop     0,2
  129. _Read             dc.l     dosbased
  130.                   dc.w     %1110,$ffd6,-1
  131.  
  132. * Write           (s length buffer file -- length )
  133. ; Dos Write function.
  134.                   dc.w     -1
  135.                   dc.l     doslink3
  136. doslink3          set      *-4
  137.                   dc.b     $85,'Writ',$80!'e'
  138.                   cnop     0,2
  139. _Write            dc.l     dosbased
  140.                   dc.w     %1110,$ffd0,-1
  141.  
  142. * Seek            (s mode position file -- oldposition )
  143. ; Dos' Seek function.
  144.                   dc.w     -1
  145.                   dc.l     doslink3
  146. doslink3          set      *-4
  147.                   dc.b     $84,'See',$80!'k'
  148.                   cnop     0,2
  149. _Seek             dc.l     dosbased
  150.                   dc.w     %1110,$ffbe,-1
  151.  
  152. * IoErr           (s -- error )
  153. ; Dos' IoErr function, returns integer error number.
  154.                   dc.w     -1
  155.                   dc.l     doslink1
  156. doslink1          set      *-4
  157.                   dc.b     $85,'IoEr',$80!'r'
  158.                   cnop     0,2
  159. _IoErr            dc.l     dosbased
  160.                   dc.w     %0,$ff7c,-1
  161.  
  162.  
  163.